import java.awt.Font;
import java.awt.Frame;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;


/** add a chosen book to the reader's "shopping cart" for later purchase */
public class AddToCart extends JDialog {

	private static final long serialVersionUID = 1L;
	/** dialog panel */
	private JPanel jContentPane = null;
	/** chose label */
	private JLabel choose = null;
	/** ok button, after chosing language */
	private JButton ok = null;
	/** holds the available languages for this book */
	private String[] languages;
	/** language combobox */
	private JComboBox lanLabel = null;
	/** language label */
	private JLabel lanLabel1 = null;
	/** holds the book serial */
	private String serial;
	/** cancel button, go to main screen */
	private JButton cancel = null;
	/** holds the available formats for this book */
	public Boolean[] formats = null;
	
	/**
	 * initializes the book information
	 * @param owner
	 */
	public AddToCart(Frame owner,Boolean[] f,String[] lan,String serial) {
		super(owner);
		formats=f;
		languages=lan.clone();
		this.serial=serial;
		initialize();
	}

	/**
	 * This method initializes the dialog window for add to cart 
	 */
	private void initialize() {
		this.setSize(288, 251);
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			lanLabel1 = new JLabel();
			lanLabel1.setBounds(new Rectangle(63, 55, 192, 39));
			lanLabel1.setText("Language");
			lanLabel1.setFont(new Font(Font.SANS_SERIF ,Font.BOLD,35));
			choose = new JLabel();
			choose.setBounds(new Rectangle(8, 8, 181, 37));
			choose.setText("Choose");
			choose.setFont(new Font(Font.SANS_SERIF ,Font.BOLD,35));
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(choose, null);
			jContentPane.add(getOk(), null);
			jContentPane.add(getLanLabel(), null);
			jContentPane.add(lanLabel1, null);
			jContentPane.add(getCancel(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes ok button and set listener on this button
	 * this button add a book to reader's cart	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getOk() {
		if (ok == null) {
			ok = new JButton();
			ok.setText("OK");
			ok.setBounds(new Rectangle(144, 181, 107, 24));
			ok.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					Main.searchBookC.addCart(formats,serial,(String)lanLabel.getSelectedItem());
					dispose();
				}
			});
		}
		return ok;
	}

	/**
	 * This method initializes lanLabel	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getLanLabel() {
		if (lanLabel == null) {
			lanLabel = new JComboBox(languages);
			lanLabel.setBounds(new Rectangle(102, 120, 150, 23));
			
		}
		return lanLabel;
	}

	/**
	 * This method initializes cancel button and set listener on this button
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getCancel() {
		if (cancel == null) {
			cancel = new JButton("Cancel");
			cancel.setBounds(new Rectangle(10, 181, 107, 24));
			cancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return cancel;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
